package com.zt.ztzx.controller;

import com.github.pagehelper.PageInfo;
import com.zt.ztzx.model.entity.product.ProductBatches;
import com.zt.ztzx.model.entity.system.SysRole;
import com.zt.ztzx.model.vo.common.Result;
import com.zt.ztzx.service.ProductBatchesService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("batches")
public class ProductBatchesController {

    @Autowired
    private ProductBatchesService productBatchesService;

    @GetMapping("/findAll/{pageNum}/{pageSize}")
    @Operation(summary = "产品批次列表", description = "产品批次列表",method = "findAll方法")
    @Parameters({
            @Parameter(name = "productName",description = "产品批次名称",required = true),
            @Parameter(name = "pageNum",description = "当前页码",required = true),
            @Parameter(name = "pageSize",description = "每页显示条数",required = true)
    })
    public Result<PageInfo<ProductBatches>> findAll(String productName,@PathVariable("pageNum")Integer pageNum, @PathVariable("pageSize")Integer pageSize) {
        return productBatchesService.findAll(pageNum,pageSize,productName);
    }

    @PostMapping("/save")
    @Operation(summary = "添加产品批次", description = "添加产品批次",method = "save方法")
    @Parameters({
            @Parameter(name = "productBatches",description = "产品批次信息",required = true)
    })
    public Result add(@RequestBody ProductBatches productBatches){
        return productBatchesService.add(productBatches);
    }

    @PutMapping("/update")
    @Operation(summary = "更新产品批次",description = "更新产品批次",method = "update方法")
    @Parameters({
            @Parameter(name = "productBatches",description = "产品批次信息",required = true)
    })
    public Result update(@RequestBody ProductBatches productBatches){
        return productBatchesService.updateData(productBatches);
    }



    @DeleteMapping("/remove/{id}")
    @Operation(summary = "删除产品批次",description = "删除产品批次",method = "remove方法")
    @Parameters({
            @Parameter(name = "id",description = "产品批次id",required = true)
    })
    public Result remove(@PathVariable("id")Long id){
        return productBatchesService.removeData(id);
    }
}
